package sort;

public class InsertionSort {
	private int listElements;
	private long[] list;
	
	/**
	 * insertion sort algorithm
	 */
	public InsertionSort(){
		
	}
	/**
	 * 
	 * @param incList list that is needed to be sorted out
	 * @return sorted list
	 */
	public long[] insertionSort(long[] incList){
		listElements = incList.length;
		this.list = incList;
		int in, out;
		
		for(out = 1; out < listElements; out++){
			long temp = list[out];
			in = out;
			while(in > 0 && list[in-1]>=temp){
				list[in] = list[in-1];
				in--;
			}
			list[in] = temp;
		}
		return list;
	}
	/**
	 * print the list
	 * @param incList list that will be printed
	 */
	public void printList(long[] incList){
		int listElements = incList.length;
		System.out.println("\ninsertionSort \n");
		for(int i = 0; i < listElements; i++){
			System.out.print(incList[i] + ", ");
		}
	}
}
